<?php

/**
 * LEAGUEMan
 * 
 * Copyright (C) 2007 Marko Bischof
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
class LM_Table_Round extends LM_Table
{
    /** @var int Primary Key */
    public $round_id;
    /** @var string round name */
    public $round_name;
    /** @var string round name */
    public $round_name_short;
    /** @var int references LM_Table_Project */
    public $round_project;
    /** @var int ordering */
    public $ordering;
    /** @var int counter */
    public $hits;
    /** @var int content_id */
    public $content_id;
    /** @var int showResults */
    public $showResults;
    /** @var int showTable */
    public $showTable;
    /** @var int showInfo */
    public $showInfo;

    /**
     * constructor
     * @param object $db mosDatabase
     */
    public function __construct($db)
    {
        parent::__construct('#__leagueman_round', 'round_id', $db);
    }

    /**
     * function getRoundId
     * @return int 
     */
    public function getID()
    {
        return $this->round_id;
    }

    /**
     * function getRoundName
     * @return int 
     */
    public function getName()
    {
        return $this->round_name;
    }

    /**
     * function getRoundName
     * @return int 
     */
    public function getShortName()
    {
        return $this->round_name_short;
    }

    /**
     * function getOrdering
     * @return int 
     */
    public function getOrdering()
    {
        return $this->ordering;
    }

    /**
     * function getHits
     * @return int 
     */
    public function getHits()
    {
        return $this->hits;
    }

    public function hasOption($option)
    {
        if (in_array($option, array('showResults', 'showTable', 'showInfo'))) {
            return $this->$option;
        }

        return false;
    }

    public function hasOptions()
    {
        return $this->showResults == 1 || $this->showTable == 1 || $this->showInfo == 1;
    }

    /**
     * function loadByOrdering
     * @param int $p references LM_Table_Project
     * @param int $r this->ordering
     * @return mixed 
     */
    public function loadByOrdering($p, $r)
    {
        $p = $this->_db->Quote(intval($p));
        $r = $this->_db->Quote(intval($r));

        $this->_db->setQuery(
                "SELECT * FROM #__leagueman_round
                  WHERE round_project = $p
                    AND ordering = $r
                  LIMIT 1"
        );

        return $this->_db->loadObject($this);
    }

}